Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports Csla
Imports Csla.Data
Imports Csla.Validation

<Serializable()> _
Public Class ro_leagueChild
    Inherits Csla.ReadOnlyBase(Of ro_leagueChild)

#Region " Business Properties and Methods "

    ' declare members
    Private _leagueId As Integer = 0
    Private _leagueName As String = String.Empty
    Private _createDate As SmartDate = New SmartDate(DateTime.Today)

    ''' <summary>
    ''' Get the LeagueId of the current object.
    ''' </summary>
    ''' <value>A Integer that represents the LeagueId of the current object.</value>
    ''' <returns>Integer representing the return value.</returns>
    ''' <remarks></remarks>
    <System.ComponentModel.DataObjectField(True, True)> _
    Public ReadOnly Property LeagueId() As Integer
        Get
            CanReadProperty("LeagueId", True)
            Return _leagueId
        End Get
    End Property

    ''' <summary>
    ''' Get the LeagueName of the current object.
    ''' </summary>
    ''' <value>A String that represents the LeagueName of the current object.</value>
    ''' <returns>String representing the return value.</returns>
    ''' <remarks></remarks>
    Public ReadOnly Property LeagueName() As String
        Get
            CanReadProperty("LeagueName", True)
            Return _leagueName
        End Get
    End Property

    ''' <summary>
    ''' Get the CreateDate of the current object.
    ''' </summary>
    ''' <value>A DateTime that represents the CreateDate of the current object.</value>
    ''' <returns>DateTime representing the return value.</returns>
    ''' <remarks></remarks>
    Public ReadOnly Property CreateDate() As DateTime
        Get
            CanReadProperty("CreateDate", True)
            Return _createDate.Date
        End Get
    End Property

    ''' <summary>
    ''' Get the CreateDateString of the current object.
    ''' </summary>
    ''' <value>A String that represents the CreateDateString of the current object.</value>
    ''' <returns>String representing the return value.</returns>
    ''' <remarks></remarks>
    Public ReadOnly Property CreateDateString() As String
        Get
            CanReadProperty("CreateDateString", True)
            Return _createDate.Text
        End Get
    End Property

    ''' <summary>
    ''' Get the unique id for the current object.
    ''' </summary>
    ''' <returns>A value that is the unique id of the object.</returns>
    ''' <remarks></remarks>
    Protected Overrides Function GetIdValue() As Object
        Return _leagueId
    End Function

    Public Overrides Function ToString() As String
        Return _leagueName
    End Function

#End Region ' Business Properties and Methods

#Region " Authorization Rules "

    Protected Overrides Sub AddAuthorizationRules()
        'TODO: Define authorization rules in ro_leagueChild
        'AuthorizationRules.AllowRead("LeagueId", "ro_leagueChildReadGroup")
        'AuthorizationRules.AllowRead("LeagueName", "ro_leagueChildReadGroup")
        'AuthorizationRules.AllowRead("CreateDate", "ro_leagueChildReadGroup")
        'AuthorizationRules.AllowRead("CreateDateString", "ro_leagueChildReadGroup")

    End Sub

#End Region ' Authorization Rules

#Region " Factory Methods "

    Friend Shared Function GetLeagueChild(ByVal dr As SafeDataReader) As ro_leagueChild
        Return New ro_leagueChild(dr)
    End Function

    Private Sub New(ByVal dr As SafeDataReader)
        Fetch(dr)
    End Sub

#End Region ' Factory Methods

#Region " Data Access "

#Region " Data Access - Fetch "

    Private Sub Fetch(ByVal dr As SafeDataReader)
        FetchObject(dr)

        'load child object(s)
        FetchChildren(dr)
    End Sub

    Private Sub FetchObject(ByVal dr As SafeDataReader)
        _leagueId = dr.GetInt32("leagueId")
        _leagueName = dr.GetString("leagueName")
        _createDate = dr.GetSmartDate("createDate", _createDate.EmptyIsMin)
    End Sub

    Private Sub FetchChildren(ByVal dr As SafeDataReader)
    End Sub

#End Region ' Data Access - Fetch

#End Region

End Class

